package com.boot;

import com.boot.controller.MessageProducer;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class MyMain {
    public static void main(String[] args) {
        SpringApplication.run(MyMain.class, args);
    }

    @Bean
    public CommandLineRunner demo(MessageProducer messageProducer) {
        return args -> {
            for (int i = 0; i < 10; i++) {
                messageProducer.sendMessage("Message " + i);
                Thread.sleep(5000);
            }
            System.out.println("\n=== 消息发送完成 ===");
            System.out.println("现在可以手动关闭一个节点(如zhima)");
            System.out.println("观察消费者是否继续工作\n");

            //保持程序运行，持续消费
            Thread.sleep(Long.MAX_VALUE);
        };
    }
}
